import pandas as pd
import numpy as np

#打开文件
data = pd.read_csv('筛选后自变量.csv')
#相关系数矩阵
corrdf = data.corr()
#print(corrdf)

#求特征值，特征向量
a,b=np.linalg.eig(corrdf)
sum = 0
s = 0
for i in range(len(a)):
    sum = sum + a[i]
print(sum)
for i in range(len(a)):
    s = s + a[i]/sum
    print('特征值：', a[i], '贡献率：', (a[i]/sum), '累计贡献率：', s, '对应特征向量为：', b[:, i])